<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2016/11/7
  Time: 13:27
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/mb/jsp/common.jsp" %>

<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>团队列表</title>
</head>
<body ontouchstart="">
<div class="detailTop pf w100 of">
    <div id="recordTop" class="w100 of tc cf f18">
        <span class="pa" style="left: 5px;" onclick="javascript:history.back();"><img src="mb/images/top_back_white.png" style="margin-top: 4px;height: 40px;width: 40px;"/></span>
        	团队列表
    </div>
</div>

<div id="container" class="container jz" style="padding-bottom: 0;padding-top: 55px;width:1200px;">

    
    <div id="resText"></div><!--resText-->
      
        <div id="loading" class="w100">
            <img src="mb/images/loading.gif" alt="正在加载" class="db jz hauto" style="width: 15px;">
            <div class="w100 tc f10 c9">正在加载</div>
        </div>
         <div id="loadingComplete" class="w100" style="display:none;">
            <div class="w100 tc f12 c9">已加载完所有数据</div>
        </div>
    
</div>
 <script>
   //获取url中的参数
        function getUrlParam(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
            var r = window.location.search.substr(1).match(reg);  //匹配目标参数
            if (r != null) return unescape(r[2]); return null; //返回参数值
        }
        
     var keyword = decodeURIComponent(getUrlParam('keyword'));
	  
	var total = 0;  
	var curpage = 1;
   //加载新数据
    function getData() {
     console.log("keyword: " +keyword);
        $.ajax({
            url: "PlugServlet",
            data: JSON.stringify({m:1785,curpage:curpage,keyword:keyword}),
            type: 'post',
            dataType: 'json',
            contentType: "application/json;charset=utf-8",
            beforeSend: function () {
                showProgressDg();
            },
            success: function (data) {
               if (data.state == 1) {
               	  total = data.total;
                  showData(data.list);
                } else {
                    // 其他错误弹出提示
                    showToast(data.info);
                }
            },
            error: function (data) {
                showToast(data.info);
            },
            complete: function () {
                closeProgressDg();
            }
        });
         return total;
         
    }

 function showData(list)
    {
    	var htmlStr="";
    	$.each(list, function(index, obj) 
    	{
    		htmlStr +=
		    		'<section class="teamList pr w100 bcf">'+
						   '<div class="w100 jz clearfix of">'+
							   	'<div class="fl imgBlock of">'+
							      	'<img src="'+getImageBasePath(obj.avatar)+'" class="w100 h100">'+
							    '</div>'+
							    '<div class="fl mgl10">'+
								     '<p class="f14 c3 lh18">'+obj.username+'</p>'+
								     '<p class="c9 f12 mgt13">'+obj.time+'</p>'+
							    '</div>'+
							    '<div class="fr">'+
							      	'<p class="f14 c3 lh18">'+obj.level+'</p>'+
							    '</div>'+
						   '</div>'+
					  '</section>';
	    		   		
    	});
    	 $("#resText").after(htmlStr);
    	
    	
    }
   
 
	$(document).ready(function(){
	
	getData();
	
			$(window).scroll(function () {
	        if ($(window).scrollTop() == $(document).height() - $(window).height()) {
		           if (curpage < total) {
		               curpage++;
		                $("#loading").slideDown();
		               getData();
		               $("#loading").slideUp();
	              }
	              else {
		               	$("#loadingComplete").slideDown();
		               	var close = function (){
		               	  $("#loadingComplete").slideUp()
		               	};
		   				setTimeout(close,3000);
		   				clearTimeout(close); 
		   				return false;
	              } 
	              
	        }
	 
	    });
	   
	});
</script>


</body>
</html>
